/**
 * 
 */
package com.maohi.software.arii;

import java.util.Set;

import org.apache.log4j.Logger;

import com.maohi.software.arii.exceptions.ActivatorException;
import com.maohi.software.arii.interfaces.Activator;

/**
 * @author heifara
 * 
 */
public class ActivatorImpl implements Activator, Runnable {
	private static Logger logger = Logger.getLogger(ActivatorImpl.class.getName());
	private boolean running;
	private Console console;

	@Override
	public void init() throws ActivatorException {
	}

	@Override
	public void run() {
		logger.debug(String.format("starting Arii"));

		this.console = new Console("Arii");

		this.running = true;
		while (this.running) {
			try {
				final String iUserInput = this.console.showPrompt();
				if (iUserInput.isEmpty()) {
					continue;
				} else if (iUserInput.equals("exit")) {
					this.running = false;
					Arii.exit();
				} else if (iUserInput.split(" ")[0].contains("service")) {
				} else if (iUserInput.split(" ")[0].contains("thread")) {
					if (iUserInput.split(" ")[1].contains("list")) {
						final Set<Thread> iThreads = Thread.getAllStackTraces().keySet();
						for (final Thread iThread : iThreads) {
							System.out.println(iThread.getName() + "\n");
						}
					}
				} else {
					System.out.println("command not found");
				}
			} catch (final Exception aException) {
				logger.error(String.format("%s", aException.getMessage()), aException);
			}
		}
	}

	@Override
	public void start() {
		Thread iThread = new Thread(this);
		iThread.setName("Arii");
		iThread.start();
	}

	@Override
	public void stop() {
	}

}
